//----------------------------------Include-------------------------------------
#include <stdio.h>
#include <string.h>
#include <stdint.h>

#include "glbvar.h"
#include "mcu.h"
#include "board.h"
#include "power.h"
//------------------------------------------------------------------------------

//-----------------------------------Macro--------------------------------------
//------------------------------------------------------------------------------

//---------------------------------Static Var-----------------------------------
char txbuf[256];
//------------------------------------------------------------------------------
float temp;
//------------------------------------------------------------------------------

//--------------------------------Static Func-----------------------------------
//------------------------------------------------------------------------------

//--------------------------------Public Func-----------------------------------
int main(void)
{
  brd_init();
  
  sprintf(txbuf, "start!\r\n");
  mcu_uart1_dma_tx(txbuf, strlen(txbuf));
  
  mcu_init_iwdg();
  mcu_iwdg_en();
  while(1){
    mcu_iwdg_feed();
    power_cyc();
    temp  = mcu_get_temp();
    
    sprintf(txbuf, "frq:%0.2f\tIA:%0.0f\t\tIB:%0.0f\t\tU:%0.1f\t\tT:%0.2f\r\n", 
                    gf_ufreq, gf_rmsIA, gf_rmsIB, gf_rmsU, temp);
    mcu_uart1_dma_tx(txbuf, strlen(txbuf));
    
    mcu_delay_ms(2000);
  }
  
  return 0;
}
//------------------------------------EOF---------------------------------------


//uint8_t eewbuf[20];
//uint8_t eerbuf[2048];
//sprintf((char*)eewbuf, "hello,world!eepromok");
//brd_24c16_wr_n_byte(2048-40, eewbuf, 20);
//brd_24c16_rd_n_byte(0, eerbuf, 2048);

//sprintf((char*)eewbuf, "hello,world!flashok!");
//mcu_flash_wr_n_byte(0x0800FE00, eewbuf, 20);
//mcu_flash_rd_n_byte(0x0800FC00, eerbuf, 1024);

